<link rel="stylesheet" href="__ROOT__/static/plugs/layui/css/layui.css?at={:date('md')}">
{block name="content"}
<div class="layui-form layui-card">
    <div class="layui-card-body">
        <blockquote class="clear layui-elem-quote">用户信息</blockquote>
        <table class="layui-table">
            <colgroup>
                <col width="120">
                <col width="280">
                <col>
            </colgroup>
            <tbody>
            <tr>
                <td>会员昵称</td>
                <td>{$user_info.nickname}</td>
            </tr>
            </tbody>
        </table>
        <blockquote class="clear layui-elem-quote">订单详情</blockquote>
        <table class="layui-table">
            <colgroup>
                <col width="120">
                <col width="280">
            </colgroup>
            <tbody>
            <tr>
                <td>订单号</td>
                <td>{$order_info.top_no}</td>
            </tr>
            <tr>
                <td>订单状态</td>
                <td><span class="layui-badge layui-bg-green">{$order_status[$order_info['pay_status']]}</span></td>
            </tr>
            <tr>
                <td>付款方式</td>
                <td>
                    {$pay_type[$order_info['pay_type']]}
                </td>
            </tr>
            <tr>
                <td>付款编号</td>
                <td>{$order_info.trade_no|default="-"}</td>
            </tr>
       
            </tr>
            </tbody>
        </table>
        {if !empty($return_info)}
        <blockquote class="clear layui-elem-quote">退款信息</blockquote>
        <table class="layui-table">
            <colgroup>
                <col width="120">
                <col width="280">
            </colgroup>
            <tbody>
            <tr>
                <td>退款订单编号</td>
                <td>
                    {$return_info.refund_no}
                </td>
            </tr>
            <tr>
                <td>退款状态</td>
                <td>
                    {if $return_info.status eq 0}
                    <span class="layui-badge layui-bg-green">等待退款</span>
                    {elseif $return_info.status eq 1/}
                    <span class="layui-badge layui-bg-gray">驳回</span>
                    {elseif $return_info.status eq 2/}
                    <span class="layui-badge layui-bg-gray">已退款</span>
                    {/if}
                </td>
            </tr>
            {if $return_info.status eq 0}
            <tr>
                <td>退款金额</td>
                <td>

                    <input type="text" id="money" class="layui-input layui-input-inline" style="width: 100px;"/>
                    &nbsp;&nbsp;
                    <button type="button" class="layui-btn layui-btn-sm"
                            onclick="confirm_return('{$return_info.refund_id}')">确认退款
                    </button>
                    &nbsp;&nbsp;
                    <button type="button" class="layui-btn layui-btn-sm"
                            onclick="cancel_return('{$return_info.refund_id}')">取消退款
                    </button>
                </td>
            </tr>
            {/if}
            <tr>
                <td>申请类型</td>
                <td>
                    {$apply_list[$return_info['type_index']]['name']}
                </td>
            </tr>
            <tr>
                <td>申请原因</td>
                <td>
                    {$reason_list[$return_info['reason_index']]['name']}
                </td>
            </tr>
            <tr>
                <td>退款原因</td>
                <td>
                    {$return_info.reason}
                </td>
            </tr>
            {if $return_info.status==2}
            <tr>
                <td>退款交易号</td>
                <td>
                    {$return_info.trade_no}
                </td>
            </tr>
            <tr>
                <td>退款时间</td>
                <td>
                    {$return_info.refund_time}
                </td>
            </tr>
            {/if}

            {if $return_info.status==1}
            <tr>
                <td>拒绝原因</td>
                <td>
                    {$return_info.reject_des}
                </td>
            </tr>
            <tr>
                <td>拒绝时间</td>
                <td>
                    {$return_info.reject_time}
                </td>
            </tr>
            {/if}
            </tbody>
        </table>
        {/if}
        <blockquote class="clear layui-elem-quote">产品信息</blockquote>
        <table class="layui-table">
            <thead>
            <tr>
                <th>产品名称</th>
                <th>单价</th>
                <th>数量</th>
                <th>状态</th>
                <th>销售员工</th>
                <th>产品总价</th>
                <th>出售时间</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>{$order_info['stu_name']}</td>
                <td>{$order_info['third_pay']}</td>
                <td></td>
                <td>
                    {$pay_type[$order_info['pay_type']]}
                </td>
                <td>{$order_info.emp_name|default='无'}</td>
                <td>{$order_info.real_pay}</td>
                <td>
                    {$order_info['pay_time']}
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>
{/block}
{block name='script'}
<script>
    var ajax = false;

    function cancel_return(rid) {
        if (ajax) return;
        layer.confirm('是否取消退款？', {
            btn: ['确定', '取消']
        }, function () {
            ajax = true;
            $.ajax({
                type: 'post',
                url: "{:url('Order/cancelReturn')}",
                data: {id: rid},
                dataType: 'json',
                success: function (data) {
                    ajax = false;
                    layer.alert(data.info, function () {
                        parent.window.location.reload();
                    });
                }
            });
        }, function () {
            layer.closeAll();
        });
    }

    function trans(trans_no, com) {
        $.post("{:url('Logistics/queryOrder')}", {no: trans_no}, function (data) {
            if (data.msg == 'ok') {
                var html = "<div style=\"display: flex;background-color: #e7466f;color: #fff;padding: 5px;\"><div class='topExpress-left'>\n" +
                    "  <img src='" + data.result.logo + "' style='margin-top: 10%;width:60%;height:60%;border-radius:50%;'/>\n" +
                    "</div>\n" +
                    "<div class='topExpress-right'>\n" +
                    "  <div class='topExpress-right-top'>" + data.result.expName + "</div>\n" +
                    "  <div class='topExpress-right-middle'>运单号：" + data.result.number + "</div>\n" +
                    "  <div class='topExpress-right-bottom'>官方电话 <a style='color: #fff' href='tel:" + data.result.expPhone + "'>" + data.result.expPhone + "</a></div>\n" +
                    "</div></div>";
                html += "<div style=\"text-align: left;margin: 10px auto\"><div class='expressRecord'>\n" +
                    "    <div class='expressRecord-getAddress'>\n" +
                    "      <div class='expressRecord-top'>\n" +
                    "        <div class='getAddress-icon'>\n" +
                    "          收\n" +
                    "        </div>\n" +
                    "        <div class='getAddress-text'>[收货地址]" + data.result.address + "</div>\n" +
                    "      </div>\n" +
                    "    </div>\n" +
                    "\n" +
                    "    <div class='noReach-online-top-close'></div>";
                $.each(data.result.list, function (n, item) {
                    html += "<div class='expressRecord-single-close'>\n" +
                        "\n" +
                        "      <!-- 左边子容器 -->\n" +
                        "      <div class='expressRecord-single-noReach-online-top-close'>\n" +
                        "        <!-- 正在进行的时间轴上半个时间线 -->\n" +
                        "        <div class='" + (n == 0 ? 'online-top-closing' : 'online-top-close') + "'></div>\n" +
                        "        <!-- 正在进行的时间轴点 -->\n" +
                        "        <div class='" + (n == 0 ? 'dot-closing' : 'dot-close') + "'></div>\n" +
                        "        <!-- 正在进行的时间轴下半个时间线 -->\n" +
                        "        <div class='online-bottom" + (n == (data.result.list.length - 1) ? '-start' : '') + "'></div>\n" +
                        "      </div>\n" +
                        "\n" +
                        "      <!-- 右边子容器 -->\n" +
                        "      <div class='expressRecord-text'>\n" +
                        "        <div class='expressRecord-status-addressing'>" + item.status + "</div>\n" +
                        "      </div>\n" +
                        "\n" +
                        "      <!-- 相对父级容器绝对定位的日期 -->\n" +
                        "      <div class='expressRecord-dating'>\n" +
                        "        <div class='expressRecord-date-text'>\n" +
                        "          " + item.time_date + "\n" +
                        "        </div>\n" +
                        "        <div class='expressRecord-date-time'>\n" +
                        "          " + item.time_time + "\n" +
                        "        </div>\n" +
                        "      </div>\n" +
                        "    </div>";
                })
                html += "</div></div>";
                layer.open({
                    content: '<style>.layui-layer-dialog .layui-layer-content{padding: 0}</style>' + html,
                });
            } else {
                layer.open({
                    content: data.msg,
                    btn: '我知道了'
                });
            }

        }, 'json');
    }

    //确认退款
    function confirm_return(return_id) {
        var money = parseFloat($('#money').val());
        if (isNaN(money)) {
            layer.msg('填写金额错误');
            return;
        }
        if (ajax) return;
        layer.prompt({formType: 1, title: '请输入交易密码'}, function (value, index) {
            if (ajax) return;
            ajax = true;
            $.ajax({
                type: 'post',
                url: "{:url('Order/confirmReturn')}",
                data: {'id': return_id, 'money': money, 'password': value},
                dataType: 'json',
                success: function (data) {
                    ajax = false;
                    if (data.code == 1) {
                        layer.alert('退款成功~', function () {
                            parent.layer.closeAll();
                            parent.window.location.reload();
                        });
                    } else if (data.code == -1) {
                        layer.open({
                            content: data.info
                            , btn: '我知道了',
                            yes: function (index) {
                                layer.close(index);
                            }
                        });
                    }
                }
            });
        });
    }
</script>
{/block}